﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using JWBST.CommonClass;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace XWG.JWBST.JWBSTManagementApp
{
    /// <summary>
    /// DownLoadService 的摘要说明
    /// </summary>
    public class DownLoadService : JWBSTAPP.CommonClass.WebHandlerBase, System.Web.SessionState.IRequiresSessionState
    {

        //public void ProcessRequest(HttpContext context)
        //{
        //    context.Response.ContentType = "text/plain";
        //    context.Response.Write("Hello World");
        //}

        //public bool IsReusable
        //{
        //    get
        //    {
        //        return false;
        //    }
        //}


        /// <summary>
        /// 更新下载量
        /// </summary>
        [WebMethod]
        public void AddDownloads()
        {
            string callback = HttpContext.Current.Request["para"];
            int num = JWBSTBLL.TbBstDownLoad.GetLastDownLoad();
            num = num + 1;
            JWBSTBLL.TbBstDownLoad.UpdateDownLoad(num);

            HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            var result = JsonUtils.ConvertJsonString(JsonConvert.SerializeObject(JWBSTBLL.TbBstDownLoad.GetLastDownLoad()));
            //HttpContext.Current.Response.Write(callback + "(" + result + ")");
            HttpContext.Current.Response.Write(callback + "([{ 'value' :" + result + " }])");
            HttpContext.Current.Response.End();
        }

        /// <summary>
        /// 更新下载量
        /// </summary>
        [WebMethod]
        public void GetDownloads()
        {
            string callback = HttpContext.Current.Request["para"];
            //HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            //var result = JsonUtils.ConvertJsonString(JsonConvert.SerializeObject(Convert.ToString(JWBSTBLL.TbBstDownLoad.GetLastDownLoad())));
            //string json = JsonConvert.SerializeObject(JWBSTBLL.TbBstDownLoad.GetLastDownLoad());
            //JObject rejson = (JObject)JsonConvert.DeserializeObject(json);
            //rejson.Add("value", rejson);

            //HttpContext.Current.Response.Write(callback + "(" + result + ")");
            //HttpContext.Current.Response.End();
            //IsoDateTimeConverter dtConverter = new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" };
            HttpContext.Current.Response.Charset = "GB2312";
            HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            var result = JsonUtils.ConvertJsonString(JsonConvert.SerializeObject(JWBSTBLL.TbBstDownLoad.GetLastDownLoad()));
            //HttpContext.Current.Response.Write(callback + "(" + result + ")");
            HttpContext.Current.Response.Write(callback + "([{ 'value' :" + result + " }])");
            HttpContext.Current.Response.End();
        }

    }
}